/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-17 12:05:11
 * @LastEditTime: 2021-04-18 12:23:09
 */
class SyncLoopHook {
    constructor(args) {
        this.hooks = [];
    }

    tap(name, task) {
        this.hooks.push(task);
    }

    call(...res) {
        this.hooks.forEach((hook) => {
            let ret;
            do {
                ret = hook(...res);
            } while (ret != undefined);
        })
    }
}

let num = 0;
let syncloophook = new SyncLoopHook(['name', 'age']);
syncloophook.tap('node', (name, age) => {
    console.log('node', name, age);
    return ++num === 3 ? undefined : '来自外部';
});

syncloophook.tap('vue', (data) => {
    console.log('vue', data)
    // return '来自node'
});

syncloophook.tap('react', (data) => {
    console.log('react', data)
    // return '来自vue'
});

syncloophook.call('wq', 12);


